#include "input.h"



  void getInput()
 {
    SDL_Event event;
    int reading;
    
    
    while (SDL_PollEvent(&event))
    {
        switch (event.type)
        {

            case SDL_QUIT:
                exit(0);
            break;

            case SDL_KEYDOWN:
                switch (event.key.keysym.sym)
                {
                    case SDLK_ESCAPE:
                        exit(0);
                    break;

                    case SDLK_DELETE:
                        input.erase = 1;
                    break;

                    case SDLK_x:
                        input.jump = 1;
                    break;

                      case SDLK_SPACE:
                        input.attack = 1;
                    break;

                    case SDLK_LEFT:
                        input.left = 1;
                    break;

                    case SDLK_RIGHT:
                        input.right = 1;
                    break;

                    case SDLK_DOWN:
                        input.down = 1;
                    break;

                    case SDLK_UP:
                        input.up = 1;
                    break;

                    case SDLK_RETURN:
                        input.enter = 1;
                    break;

                    default:
                    break;
                }
            break;

            case SDL_KEYUP:
                switch (event.key.keysym.sym)
                {
                    case SDLK_DELETE:
                        input.erase = 0;
                    break;

                    case SDLK_SPACE:
                        input.attack = 0;
                    break;

                    case SDLK_x:
                        input.jump = 0;
                    break;

                    case SDLK_LEFT:
                        input.left = 0;
                    break;

                    case SDLK_RIGHT:
                        input.right = 0;
                    break;

                    case SDLK_DOWN:
                        input.down = 0;
                    break;

                    case SDLK_UP:
                        input.up = 0;
                    break;

                    case SDLK_RETURN:
                        input.enter = 0;
                    break;

                    default:
                    break;
                }
            break;

        }

    }

    char B[2];
    char ba [500];




   

   



        reading  = read (fd, B, 1);
        {
            //printf("%s",B); 
       
            
            if (reading ==1)
            {
                
              

                if (B[0]=='A')
                {
                    input.jump = 1;
                    


                   
                }
                

               else if (B[0]=='B')
                {
                    input.left = 1;
                   
                }

                else if (B[0]=='C')
                {
                    input.right = 1;
                   
                }
                else if (B[0]=='X')
                {
                    input.jump = 0;
                    input.left = 0;
                    input.right = 0;
                }

                      

               
           }
       }
          
        

 
}



